<!--
<div bsModal #createModal="bs-modal" (onShown)="onShown()" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="createModal"
     aria-hidden="true" [config]="{backdrop: 'static'}">
    <div class="modal-dialog modal-lg">

        <div class="modal-content">

            <form #tenantCreateForm="ngForm" role="form" novalidate class="form-validation" *ngIf="active" (submit)="save()">
                <div class="modal-header">
                    <h5 class="modal-title">
                        <span>{{l("CreateNewTenant")}}</span>
                    </h5>
                    <button type="button" class="close" (click)="close()" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>

                <div class="modal-body">

                    <div class="form-group">
                        <label>{{l("TenancyName")}}</label>
                        <input #tenancyNameInput class="form-control" type="text" [ngClass]="{'edited':tenant.tenancyName}" name="tenancyName" [(ngModel)]="tenant.tenancyName" #tenancyName="ngModel" required maxlength="64" pattern="^[a-zA-Z][a-zA-Z0-9_-]{1,}$">
                    </div>
                    <div>
                        <span class="help-block text-danger" *ngIf="!tenancyName.valid && !tenancyName.pristine">{{l("TenantName_Regex_Description")}}</span>
                    </div>

                    <div class="form-group">
                        <label>{{l("Name")}}</label>
                        <input type="text" name="Name" class="form-control" [ngClass]="{'edited':tenant.name}" [(ngModel)]="tenant.name" required maxlength="128">
                    </div>

                    <div class="m-checkbox-list">
                        <label class="m-checkbox">
                            <input id="CreateTenant_UseHostDb" type="checkbox" name="UseHostDb" [(ngModel)]="useHostDb">
                            {{l("UseHostDatabase")}}
                            <span></span>
                        </label>
                    </div>

                    <div class="form-group" *ngIf="!useHostDb">
                        <label>{{l("DatabaseConnectionString")}}</label>
                        <input type="text" name="ConnectionString" class="form-control" [(ngModel)]="tenant.connectionString" [ngClass]="{'edited':tenant.connectionString}" required maxlength="1024">
                    </div>

                    <div class="form-group">
                        <label>{{l("AdminEmailAddress")}}</label>
                        <input type="email" name="AdminEmailAddress" class="form-control" [(ngModel)]="tenant.adminEmailAddress" [ngClass]="{'edited':tenant.adminEmailAddress}" required pattern="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{1,})+$" maxlength="256">
                    </div>

                    <div class="m-checkbox-list">
                        <label class="m-checkbox">
                            <input id="CreateTenant_SetRandomPassword" type="checkbox" name="SetRandomPassword" [(ngModel)]="setRandomPassword">
                            {{l("SetRandomPassword")}}
                            <span></span>
                        </label>
                    </div>

                    <div class="form-group" *ngIf="!setRandomPassword">
                        <label>{{l("AdminPassword")}}</label>
                        <input type="password" name="adminPassword" class="form-control" id="adminPassword"
                               [(ngModel)]="tenant.adminPassword" [ngClass]="{'edited':tenant.adminPassword}" [required]="!setRandomPassword"
                               #adminPassword="ngModel" validateEqual="adminPasswordRepeat" reverse="true" maxlength="32" [requireDigit]="passwordComplexitySetting.requireDigit" [requireLowercase]="passwordComplexitySetting.requireLowercase"
                               [requireUppercase]="passwordComplexitySetting.requireUppercase" [requireNonAlphanumeric]="passwordComplexitySetting.requireNonAlphanumeric" [requiredLength]="passwordComplexitySetting.requiredLength">
                    </div>

                    <div [hidden]="tenantCreateForm.form.valid || tenantCreateForm.form.pristine">
                        <ul class="help-block text-danger" *ngIf="tenantCreateForm.controls['adminPassword'] && tenantCreateForm.controls['adminPassword'].errors">
                            <li [hidden]="!tenantCreateForm.controls['adminPassword'].errors.requireDigit">{{l("PasswordComplexity_RequireDigit_Hint")}}</li>
                            <li [hidden]="!tenantCreateForm.controls['adminPassword'].errors.requireLowercase">{{l("PasswordComplexity_RequireLowercase_Hint")}}</li>
                            <li [hidden]="!tenantCreateForm.controls['adminPassword'].errors.requireUppercase">{{l("PasswordComplexity_RequireUppercase_Hint")}}</li>
                            <li [hidden]="!tenantCreateForm.controls['adminPassword'].errors.requireNonAlphanumeric">{{l("PasswordComplexity_RequireNonAlphanumeric_Hint")}}</li>
                            <li [hidden]="!tenantCreateForm.controls['adminPassword'].errors.requiredLength">{{l("PasswordComplexity_RequiredLength_Hint", passwordComplexitySetting.requiredLength)}}</li>
                        </ul>
                    </div>

                    <div class="form-group" *ngIf="!setRandomPassword">
                        <label>{{l("AdminPasswordRepeat")}}</label>
                        <input type="password" name="adminPasswordRepeat" class="form-control"
                               [(ngModel)]="tenant.adminPasswordRepeat" [ngClass]="{'edited':tenant.adminPasswordRepeat}" [required]="!setRandomPassword"
                               #adminPasswordRepeat="ngModel" [requireDigit]="passwordComplexitySetting.requireDigit" [requireLowercase]="passwordComplexitySetting.requireLowercase"
                               [requireUppercase]="passwordComplexitySetting.requireUppercase" [requireNonAlphanumeric]="passwordComplexitySetting.requireNonAlphanumeric" [requiredLength]="passwordComplexitySetting.requiredLength"
                               validateEqual="adminPassword"
                               maxlength="32">
                    </div>

                    <div [hidden]="tenantCreateForm.form.valid || tenantCreateForm.form.pristine">
                        <ul class="help-block text-danger" *ngIf="tenantCreateForm.controls['adminPasswordRepeat'] && tenantCreateForm.controls['adminPasswordRepeat'].errors">
                            <li [hidden]="!tenantCreateForm.controls['adminPasswordRepeat'].errors.requireDigit">{{l("PasswordComplexity_RequireDigit_Hint")}}</li>
                            <li [hidden]="!tenantCreateForm.controls['adminPasswordRepeat'].errors.requireLowercase">{{l("PasswordComplexity_RequireLowercase_Hint")}}</li>
                            <li [hidden]="!tenantCreateForm.controls['adminPasswordRepeat'].errors.requireUppercase">{{l("PasswordComplexity_RequireUppercase_Hint")}}</li>
                            <li [hidden]="!tenantCreateForm.controls['adminPasswordRepeat'].errors.requireNonAlphanumeric">{{l("PasswordComplexity_RequireNonAlphanumeric_Hint")}}</li>
                            <li [hidden]="!tenantCreateForm.controls['adminPasswordRepeat'].errors.requiredLength">{{l("PasswordComplexity_RequiredLength_Hint", passwordComplexitySetting.requiredLength)}}</li>
                        </ul>
                    </div>

                    <div class="form-group">
                        <label for="edition">{{l("Edition")}}</label>
                        <select id="edition" name="edition" class="form-control" [(ngModel)]="tenant.editionId" (change)="onEditionChange($event)">
                            <option *ngFor="let edition of editions" [value]="edition.value">{{edition.displayText}}</option>
                        </select>
                    </div>

                    <div [hidden]="!isSubscriptionFieldsVisible" class="m-checkbox-list">
                        <label for="CreateTenant_IsUnlimited" class="m-checkbox">
                            <input id="CreateTenant_IsUnlimited" type="checkbox" name="IsUnlimited" [(ngModel)]="isUnlimited" />
                            {{l("UnlimitedTimeSubscription")}}
                            <span></span>
                        </label>
                    </div>

                    <div [hidden]="isUnlimited || !isSubscriptionFieldsVisible" class="form-group" [ngClass]="{'has-error': !subscriptionEndDateIsValid()}">
                        <label>{{l("SubscriptionEndDate")}}</label>
                        <input type="text" #SubscriptionEndDateUtc name="SubscriptionEndDateUtc" class="form-control">
                    </div>

                    <div [hidden]="!isSubscriptionFieldsVisible" class="m-checkbox-list">
                        <label for="CreateTenant_IsInTrialPeriod" class="m-checkbox">
                            <input id="CreateTenant_IsInTrialPeriod" type="checkbox" name="IsInTrialPeriod" [disabled]="isSelectedEditionFree" [(ngModel)]="tenant.isInTrialPeriod">
                            {{l("IsInTrialPeriod")}}
                            <span></span>
                        </label>
                    </div>

                    <div class="m-checkbox-list">
                        <label for="CreateTenant_ShouldChangePasswordOnNextLogin" class="m-checkbox">
                            <input id="CreateTenant_ShouldChangePasswordOnNextLogin" type="checkbox" name="ShouldChangePasswordOnNextLogin" [(ngModel)]="tenant.shouldChangePasswordOnNextLogin">
                            {{l("ShouldChangePasswordOnNextLogin")}}
                            <span></span>
                        </label>
                        <label for="CreateTenant_SendActivationEmail" class="m-checkbox">
                            <input id="CreateTenant_SendActivationEmail" type="checkbox" name="SendActivationEmail" [(ngModel)]="tenant.sendActivationEmail">
                            {{l("SendActivationEmail")}}
                            <span></span>
                        </label>
                        <label for="CreateTenant_IsActive" class="m-checkbox">
                            <input id="CreateTenant_IsActive" type="checkbox" name="IsActive" [(ngModel)]="tenant.isActive">
                            {{l("Active")}}
                            <span></span>
                        </label>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" [disabled]="saving" class="btn btn-secondary" (click)="close()">{{l("Cancel")}}</button>
                    <button type="submit" [buttonBusy]="saving" [busyText]="l('SavingWithThreeDot')" class="btn btn-primary" [disabled]="!tenantCreateForm.form.valid || saving || !subscriptionEndDateIsValid()"><i class="fa fa-save"></i> <span>{{l("Save")}}</span></button>
                </div>
            </form>
        </div>
    </div>
</div>
-->

<div class="modal-header">
    <div class="modal-title">
        <span>{{l("CreateNewTenant")}}</span>
    </div>
</div>

<form nz-form #tenantCreateForm="ngForm" role="form" novalidate class="form-validation" (submit)="save()">

    <div nz-form-item nz-row>
        <div nz-form-label nz-col [nzSm]="6" [nzXs]="24">
            <label for="tenancyName">{{l("TenancyName")}}</label>
        </div>
        <div nz-form-control nz-col [nzSm]="14" [nzXs]="24">
            <nz-input name="tenancyName" [(ngModel)]="tenant.tenancyName" [nzSize]="'large'" required maxlength="64" pattern="^[a-zA-Z][a-zA-Z0-9_-]{1,}$"></nz-input>
        </div>
    </div>

    <div nz-form-item nz-row>
        <div nz-form-label nz-col [nzSm]="6" [nzXs]="24">
            <label for="Name">{{l("Name")}}</label>
        </div>
        <div nz-form-control nz-col [nzSm]="14" [nzXs]="24">
            <nz-input name="Name" [(ngModel)]="tenant.name" [nzSize]="'large'"></nz-input>
        </div>
    </div>

    <div nz-form-item nz-row>
        <div nz-form-label nz-col [nzSm]="6" [nzXs]="24">
        </div>
        <div nz-form-control nz-col [nzSm]="14" [nzXs]="24">
            <label name="UseHostDb" nz-checkbox [(ngModel)]="useHostDb">
                <span>{{l("UseHostDatabase")}}</span>
            </label>
        </div>
    </div>

    <div nz-form-item nz-row *ngIf="!useHostDb">
        <div nz-form-label nz-col [nzSm]="6" [nzXs]="24">
            <label for="ConnectionString">{{l("DatabaseConnectionString")}}</label>
        </div>
        <div nz-form-control nz-col [nzSm]="14" [nzXs]="24">
            <nz-input name="ConnectionString" [(ngModel)]="tenant.connectionString" [nzSize]="'large'" required maxlength="1024"></nz-input>
        </div>
    </div>

    <div nz-form-item nz-row>
        <div nz-form-label nz-col [nzSm]="6" [nzXs]="24">
            <label for="AdminEmailAddress">{{l("AdminEmailAddress")}}</label>
        </div>
        <div nz-form-control nz-col [nzSm]="14" [nzXs]="24">
            <nz-input type="email" name="AdminEmailAddress" [(ngModel)]="tenant.adminEmailAddress" [nzSize]="'large'" required pattern="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{1,})+$"
                maxlength="256"></nz-input>
        </div>
    </div>

    <div nz-form-item nz-row>
        <div nz-form-label nz-col [nzSm]="6" [nzXs]="24">
        </div>
        <div nz-form-control nz-col [nzSm]="14" [nzXs]="24">
            <label name="SetRandomPassword" nz-checkbox [(ngModel)]="setRandomPassword">
                <span>{{l("SetRandomPassword")}}</span>
            </label>
        </div>
    </div>

    <div nz-form-item nz-row *ngIf="!setRandomPassword">
        <div nz-form-label nz-col [nzSm]="6" [nzXs]="24">
            <label>{{l("AdminPassword")}}</label>
        </div>
        <div nz-form-control nz-col [nzSm]="14" [nzXs]="24">
            <nz-input name="adminPassword" [(ngModel)]="tenant.adminPassword" [nzSize]="'large'" [required]="!setRandomPassword" maxlength="32"></nz-input>
        </div>
    </div>
    <div nz-form-item nz-row>
        <div nz-form-label nz-col [nzSm]="6" [nzXs]="24">
            <label for="edition">Edition</label>
        </div>
        <div nz-form-control nz-col [nzSm]="14" [nzXs]="24">
            <nz-select name="edition" [nzSize]="'large'" [(ngModel)]="tenant.editionId" (ngModelChange)="onEditionChange()">
                <nz-option *ngFor="let edition of editions" [nzLabel]="edition.displayText" [nzValue]="edition.value * 1"></nz-option>
            </nz-select>
        </div>
    </div>

    <div nz-form-item nz-row *ngIf="isSubscriptionFieldsVisible">
        <div nz-form-label nz-col [nzSm]="6" [nzXs]="24">

        </div>
        <div nz-form-control nz-col [nzSm]="14" [nzXs]="24">
            <label name="IsUnlimited" nz-checkbox [(ngModel)]="isUnlimited">
                <span>{{l("UnlimitedTimeSubscription")}}</span>
            </label>
        </div>
    </div>

    <div nz-form-item nz-row *ngIf="!(isUnlimited || !isSubscriptionFieldsVisible)">
        <div nz-form-label nz-col [nzSm]="6" [nzXs]="24">
            <label>{{l("SubscriptionEndDate")}}</label>
        </div>
        <div nz-form-control nz-col [nzSm]="14" [nzXs]="24">
            <nz-datepicker name="subscriptionEndDateUtc" 
            [(ngModel)]="subscriptionEndDateUtc" 
            [nzPlaceHolder]="'Select date'"></nz-datepicker>
        </div>
    </div>

    <div nz-form-item nz-row *ngIf="isSubscriptionFieldsVisible">
        <div nz-form-label nz-col [nzSm]="6" [nzXs]="24">

        </div>
        <div nz-form-control nz-col [nzSm]="14" [nzXs]="24">
            <label name="IsInTrialPeriod" nz-checkbox [(ngModel)]="tenant.isInTrialPeriod">
                <span>{{l("IsInTrialPeriod")}}</span>
            </label>
        </div>
    </div>

    <div nz-form-item nz-row>
        <div nz-form-label nz-col [nzSm]="6" [nzXs]="24">

        </div>
        <div nz-form-control nz-col [nzSm]="14" [nzXs]="24">
            <label name="ShouldChangePasswordOnNextLogin" nz-checkbox [(ngModel)]="tenant.shouldChangePasswordOnNextLogin">
                <span>{{l("ShouldChangePasswordOnNextLogin")}}</span>
            </label>
        </div>

        <div nz-form-label nz-col [nzSm]="6" [nzXs]="24">

        </div>
        <div nz-form-control nz-col [nzSm]="14" [nzXs]="24">
            <label name="SendActivationEmail" nz-checkbox [(ngModel)]="tenant.sendActivationEmail">
                <span>{{l("SendActivationEmail")}}</span>
            </label>
        </div>
        <div nz-form-label nz-col [nzSm]="6" [nzXs]="24">

        </div>
        <div nz-form-control nz-col [nzSm]="14" [nzXs]="24">
            <label name="IsActive" nz-checkbox [(ngModel)]="tenant.isActive">
                <span>{{l("Active")}}</span>
            </label>
        </div>
    </div>

    <div class="modal-footer">
        <button  nz-button type="button" [nzType]="'default'" [nzSize]="'large'" (click)="close()">
            {{l("Cancel")}}
        </button>
        <button nz-button [nzType]="'primary'" [nzSize]="'large'" >
            <span>{{l("Save")}}</span>
        </button>
    </div>
</form>
